package middle;

import com.eclipsesource.json.JsonArray;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 1418. 点菜展示表
 */
public class DisplayTable {

    public static List<String> stringToIntegerArray(String input) {
        input = input.trim();
        input = input.substring(1, input.length() - 1);
        if (input.length() == 0) {
            return new ArrayList<String>();
        }

        String[] parts = input.split(",");
        List<String> output = new ArrayList<>(parts.length);
        for (int index = 0; index < parts.length; index++) {
            String part = parts[index].trim().replace("\"","");
            output.add(part);
        }
        return output;
    }

    public static List<List<String>> stringToInt2dArray(String input) {
        List<List<String>> arr = new ArrayList<>();
        JsonArray jsonArray = JsonArray.readFrom(input);
        if (jsonArray.size() == 0) {
            arr.add(new ArrayList<>());
            return arr;
        }

        for (int i = 0; i < jsonArray.size(); i++) {
            JsonArray cols = jsonArray.get(i).asArray();
            arr.add(stringToIntegerArray(cols.toString()));
        }
        return arr;
    }

    public static String int2dArrayToString(List<List<String>> array) {
        if (array == null) {
            return "null";
        }
        if (array.size() == 0) {
            return "[]";
        }

        StringBuilder sb = new StringBuilder("[");
        for (List<String> item : array) {
            sb.append(Arrays.toString(item.toArray()));
            sb.append(",");
        }

        sb.setCharAt(sb.length() - 1, ']');
        return sb.toString();
    }

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = in.readLine()) != null) {
            List<List<String>> mat = stringToInt2dArray(line);

            List<List<String>> ret = new Solution().displayTable(mat);

            String out = int2dArrayToString(ret);

            System.out.print(out);
        }
    }

    static class Solution {
        public List<List<String>> displayTable(List<List<String>> orders) {
            List<List<String>> result = new ArrayList<>();
            Set<Integer> tables = new TreeSet<>();
            Set<String> foods = new TreeSet<>();
            Map<Integer, Map<String, Integer>> foodMap = new HashMap<>();
            for (List<String> list : orders) {
                tables.add(Integer.parseInt(list.get(1)));
                foods.add(list.get(2));
                Map<String, Integer> map;
                if (foodMap.get(Integer.parseInt(list.get(1))) == null) {
                    map = new HashMap<>();
                } else {
                    map = foodMap.get(Integer.parseInt(list.get(1)));
                }
                map.put(list.get(2), map.getOrDefault(list.get(2), 0) + 1);
                foodMap.put(Integer.parseInt(list.get(1)), map);
            }
            List<String> firstRow = new ArrayList<>();
            firstRow.add("Table");
            firstRow.addAll(foods);
            result.add(firstRow);
            for (Integer table : tables) {
                List<String> item = new ArrayList<>();
                item.add(table.toString());
                for (String food : foods) {
                    item.add(foodMap.get(table).get(food) == null ? "0" : foodMap.get(table).get(food).toString());
                }
                result.add(item);
            }
            return result;
        }
    }

}
